{include file="public/header" /}
<style>
    #des, #des input {
        width: 40px;
        text-align: center;
    }

    #id {
        width: 78px;
    }

    .bs-checkbox {
        width: 36px;
        height: 40px
    }

    .fixed-table-toolbar .columns, .fixed-table-toolbar .search {
        margin-left: 0px;
        margin-top: 0px
    }

    #title span {
        float: right;
        margin-left: 3.333px;
    }

    .search {
        margin-bottom: 0px !important;
    }

    .asdlkjasd {
        background: #1ab394;
        color: #fff
    }

</style>
<body class="gray-bg">
<div class="wrapper wrapper-content {:config('adminClass.main')}">
  <div class="ibox float-e-margins">
    {include file="public/tophead"}
    {include file="public/top" /}
    <div class="ibox-content">
      {include file="public/topsection"}
      <div class="row row-lg">
        <div class="col-xs-12">
          <div class="fixed-table-toolbar">
              <a class="btn btn-default btn-outline {present name='paystate'}{eq name='paystate' value='0'}asdlkjasd{/eq}{else /}asdlkjasd{/present}" href="{:url('order',['paystate'=>0])}{present name='status'}/status/{$status}{/present}">全部</a>
              <a class="btn btn-default btn-outline {present name='paystate'}{eq name='paystate' value='1'}asdlkjasd{/eq}{/present}" href="{:url('order',['paystate'=>1])}{present name='status'}/status/{$status}{/present}">已支付</a>
              <a class="btn btn-default btn-outline {present name='paystate'}{eq name='paystate' value='2'}asdlkjasd{/eq}{/present}" href="{:url('order',['paystate'=>2])}{present name='status'}/status/{$status}{/present}">待支付</a>
          </div>
          <div class="fixed-table-toolbar">
              <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='0'}asdlkjasd{/eq}{else /}asdlkjasd{/present}" href="{:url('order',['status'=>0])}{present name='paystate'}/paystate/{$paystate}{/present}">全部</a>
              <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='1'}asdlkjasd{/eq}{/present}" href="{:url('order',['status'=>1])}{present name='paystate'}/paystate/{$paystate}{/present}">待服务</a>
              <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='2'}asdlkjasd{/eq}{/present}" href="{:url('order',['status'=>2])}{present name='paystate'}/paystate/{$paystate}{/present}">商家设置完成</a>
              <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='3'}asdlkjasd{/eq}{/present}" href="{:url('order',['status'=>3])}{present name='paystate'}/paystate/{$paystate}{/present}">已完成</a>
              <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='4'}asdlkjasd{/eq}{/present}" href="{:url('order',['status'=>4])}{present name='paystate'}/paystate/{$paystate}{/present}">售后中</a>
              <a class="btn btn-default btn-outline {present name='status'}{eq name='status' value='5'}asdlkjasd{/eq}{/present}" href="{:url('order',['status'=>5])}{present name='paystate'}/paystate/{$paystate}{/present}">后台关闭</a>
          </div>
          <div class="fixed-table-toolbar">
            <form  method="get" action="">
              <div class="pull-left search">
                {php}
                if(input('?param.name')){
                {/php}
                <div class="pull-right search">
                  <a class="btn btn-w-m btn-link" href="{:url('order')}">返回订单管理</a>
                </div>{php}
                }
                {/php}
                <div class="columns columns-right btn-group pull-left" >
                  <select class="form-control" name="search">
                    <option value="user_id">用户ID</option>
                    <option value="number">订单编号</option>
                    <option value="title" {present name='search'}{eq name='search' value='title'}selected{/eq}{/present}>标题</option>
                    <option value="user_id">服务者ID</option>
                  </select>
                </div>


                <div class="pull-right search" style="display: flex;">
                  <input name="start" type="text" id="start" class="form-control layui-input" value="{present name='start'}{$start}{/present}" placeholder=" # 起始时间" autocomplete="off" style="height:34px;width:180px;margin:0 10px;">
                  <input name="end" type="text" id="end" class="form-control layui-input" value="{present name='end'}{$end}{/present}" placeholder=" # 结束时间" autocomplete="off" style="height:34px;width:180px;margin:0 10px;">
                </div>


                <div class="pull-right search">
                  <button style="border-radius:0px; border:1px solid #e5e6e7; border-left:0px" class="btn btn-default btn-outline" type="submit">搜索</button>
                </div>
                <div class="pull-right search">
                  <input class="form-control input-outline" id="filter" type="text"
                         {php}
                         if(input('?param.name')){
                  if(input('param.name')){
                  echo "value='".input('name')."'";
                  }

                  }
                  {/php}
                  name="name" placeholder="搜索订单">
                </div>


              </div>
            </form>
          </div>
          <div class="example">
            <table data-toggle="table" data-striped="false">
              <thead>
              <tr>
                <th data-align="center">商家</th>
                <th data-align="center">下单用户</th>
                <th>订单编号</th>
                <th>订单类型</th>
                <th>订单标题</th>
                <th>金额(元)</th>
                <th>对应金币</th>
                <th>支付方式</th>
                <th>支付状态</th>
                <th>订单状态</th>
                <th>服务状态</th>
                <th>免费项目</th>
                <th>添加时间</th>
                <th>更新时间</th>
                <th>管理</th>
              </tr>
              </thead>
              <tbody>
              {php}
                $status=array('-1'=>'btn-default','0'=>'btn-primary','1'=>'btn-danger','2'=>'btn-success');
              {/php}
              {volist name="data" id="v"}
              <tr id="id{$v.id}">
                <td>
                  <a onclick="member('{$v.shopowner}')" style="color:#40BCF7">{$v.shopowner_name}<br />({$v.shopowner})</a>
                </td>
                <td>
                  <a onclick="member('{$v.user_id}')" style="color:#40BCF7">{$v.name}<br />({$v.user_id})</a>
                </td>
                <td>{$v.number}</td>
                  <td>
                    {eq name="v.type" value="0"}
                    <span class='btn btn-primary btn-xs'>线上</span>
                    {else}
                    <span class='btn btn-warning btn-xs'>线下</span>
                    {/eq}
                  </td>
                <td>{$v.title}</td>
                <td>{$v.price}</td>
                <td>{$v.volley}</td>
                <td>{$v.paymethod_name}</td>
                <td><span style="color: {eq name='v.paystate' value='1'}green{else}red{/eq}">{$v.paystate_name}</span></td>
                <td><span class="btn btn-xs {eq name='v.state' value='0'}btn-primary{else}btn-default{/eq}{if condition='$v.state==0&&$v.status==-1'} btn-warning{/if}">{$v.orderstate_name}</span></td>
                <td><span class="btn btn-xs {$status[$v['status']]}{eq name='v.paystate' value='0'} btn-default{/eq}">{$v.orderstatus_name}</span></td>
                  <td>
                    {if condition="$v.method == 1"}
                    <span>文字</span>
                    {elseif condition="$v.method == 2"}
                    <span>文字+语音</span>
                    {elseif condition="$v.method == 3"}
                    <span>文字+视频</span>
                    {elseif condition="$v.method == 4"}
                    <span>文字+语音+视频</span>
                    {/if}
                  </td>
                <td>{$v.create_time|date='Y-m-d H:i:s',###}</td>
                <td>{$v.update_time|date='Y-m-d H:i:s',###}</td>
                <td>
                  <div class="btn-group">
                    <button data-toggle="dropdown" class="btn btn-primary btn-xs dropdown-toggle">操作 <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                      {if condition="($v.status == 1 || $v.status == 0) && $v.state == 0"}
                      <li><a onclick="setStatus({$v.id}, -1)">开始售后</a>
                      <li><a onclick="setStatus({$v.id}, 2)">设置为已完成</a>
                      </li>
                      {elseif condition="$v.status == -1 && $v.state == 0"}
                      <li><a onclick="setStatus({$v.id}, 1)">取消售后</a>
                      <li><a onclick="setStatus({$v.id}, -4)">售后完成</a>
                      </li>
                      {/if}
                      <li><a onclick="del({$v.id})">删除</a>
                      </li>
                    </ul>
                  </div>
                </td>
              </tr>
              {/volist}
              </tbody>
            </table>
          </div>
        </div>
      </div>
      <hr>
      <div class="row row-lg">
        <div class="col-sm-12 pages">{$page}</div>
      </div>
    </div>
  </div>
</div>
{include file="public/footer" /}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.css"}
{load href="__PLUGINS__bootstrap/bootstrap-table.min.js"}
{load href="__PLUGINS__bootstrap/bootstrap-table-zh-CN.min.js"}
<script type="text/javascript">
  $(document).ready(function(){
    layui.use(['laydate'], function(){
        var laydate = layui.laydate;

        laydate.render({
            elem: '#start' //指定元素
            ,type: 'datetime'
            ,trigger: 'click'
        });

        laydate.render({
            elem: '#end' //指定元素
            ,type: 'datetime'
            ,trigger: 'click'
        });
    })
  });
  function del(id){
    swal_del(id,"{:url('delOrder')}")
  }
  function member(id)
  {
      layui.use('layer', function(){
          var layer = layui.layer;
          layer.open({
              title :'预览',
              area: ['100%', '100%'],
              type: 2,
              content: '{:url("member/index")}?search=id&name='+id
          });
      });
  }

  function setStatus(id,status){
    let url = "{:url('setStatus')}?status=" + status
    swal({
        title: "您确定要执行此操作吗",
        text: "操作后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "确定",
        cancelButtonText: "取消",
    },
    function(isConfirm) {
        if (isConfirm) {
            var index = layer.load(1, {
             shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            ajaxFun("post",url,{id:id},'json',function(ret){
                if(ret){
                    if(ret.ret){
                      setTimeout(()=>{
                        swal_msg(ret.ret,'','success',1)
                      }, 100)
                    }else{
                        layer.msg(ret.err)
                    }
                }else{
                    swal_msg("错误",ret,"error");
                }
                layer.close(index); 
            })
        }
    })
  }

</script>